package com.sac.common.exception;

import com.sac.common.utils.ShiroUtils;
import com.sac.common.utils.WebSocketUtil;
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.mail.MailSendException;
import org.springframework.messaging.MessagingException;
import org.springframework.stereotype.Component;
import org.terracotta.modules.ehcache.async.exceptions.AsyncException;

import java.lang.reflect.Method;

/**
 * @author xiaodong
 * @title
 * @date 2018/12/5 13:22
 * @desc
 */
@Component
public class AsyncExceptionHandler implements AsyncUncaughtExceptionHandler {

    @Override
    public void handleUncaughtException(Throwable ex, Method method, Object... params) {
        if (ex instanceof AsyncException) {
            AsyncException asyncException = (AsyncException) ex;
        }else if(ex instanceof MailSendException){
            System.out.println("Mail Exception:"+ex.getLocalizedMessage());
            WebSocketUtil.pushMailSendingFailedNotification(ShiroUtils.getEmpId(), "邮件发送失败");
        }else if(ex instanceof MessagingException){

        }
        ex.printStackTrace();
    }
}
